home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / NetMouse ƒ / NetMouse Xmt / Kennedy INIT.c next >
Encoding:
C/C++ Source or Header  |  1992-06-22  |  7.4 KB  |  366 lines  |  [TEXT/KAHL]

  1. // This code was written Thursday June 22, 1992 by Jorg 'jbx' Brown.
  2. // This code is not freeware; this code is public domain.
  3.  
  4. // Written in Think C 5.0.  Anything less would be unthinkable.
  5.  
  6. #undef SystemSevenOrLater
  7. #define SystemSevenOrLater 1
  8.  
  9. #include "Misc.h"
  10. #include <GestaltEqu.h>
  11. #include <PPCToolbox.h>
  12. #include <EPPC.h>
  13. #include <AppleEvents.h>
  14. #include <Retrace.h>
  15.  
  16. static void pJGNEFilter(void);
  17.  
  18. static    short    PPC_waiting = 1;
  19. static    short    call_inform = 0;
  20. static    char    buffer[512];
  21. static    short    new_mouse;
  22. short    whichReader = 1;
  23. PPCReadPBRec    Reader1, Reader2;
  24.  
  25. static void pJGNEFilter(void);
  26.  
  27. long oldPostEvent, oldButton;
  28. static void pPostEvent(void);
  29. static void pButton(void);
  30.  
  31. void main(void) {
  32. short    i, j;
  33.     SetA4(&main);
  34.     asm {
  35.         lea        @pj+2,a0
  36.         move.l    JGNEFilter,(a0)
  37.         bne.s    @nrm
  38.         move.w    #0x4E75,-2(a0)
  39. nrm:    lea        @ptch,a0
  40.         move.l    a0,JGNEFilter
  41.     };
  42.  
  43.     oldPostEvent = GetOSTrapAddress(0xA12F);
  44.     SetOSTrapAddress((long) &pPostEvent, 0xA12F);
  45.  
  46.     oldButton = GetToolTrapAddress(0xA974);
  47.     SetToolTrapAddress((long) &pButton, 0xA974);
  48.  
  49.     DetachResource(RecoverHandle(&main));
  50.  
  51.     for (i = 1000; i < 1006; i++) {
  52.         ShowINIT(0, i);
  53.         jbxDelay(15);
  54.     }
  55.     ShowINIT(1006, 0);
  56.     
  57.     for (i = 2000; i < 2004; i++) {
  58.         ShowINIT(0, i);
  59.         jbxDelay(15);
  60.     }
  61.     ShowINIT(2004, 0);
  62.     
  63.     return;
  64.  
  65.     if (0) asm {    /* let's not execute the patch code, shall we? */
  66. ptch:    cmpi.w    #nullEvent,OFFSET(EventRecord, what)(a1)
  67.         bne        @pj
  68.         movem.l    a0-a1/a4/d0-d2,-(a7)
  69.         lea        main,a4
  70.         move.l    a1,-(a7)
  71.         jsr        pJGNEFilter
  72.         addq    #4,a7
  73.         movem.l    (a7)+,a0-a1/a4/d0-d2
  74.         cmpi.w    #nullEvent,OFFSET(EventRecord, what)(a1)
  75.         beq.s    @pj
  76.         moveq    #1,d0
  77.         move.w    d0,4(a7)
  78. pj:        jmp        0x12345678
  79.     }
  80. }
  81.  
  82. extern Point Mouse : 0x830;
  83. extern char MBState : 0x172;
  84. extern char CrsrBusy : 0x8CD;
  85.  
  86. static
  87. short qRelString(void *first, void *second) {
  88.     asm {
  89.         moveq    #-1, d0
  90.         move.l    first,a0
  91.         move.l    second,a1
  92.  
  93.         move.b    1(a0),d1
  94.         cmpi.b    #'a',d1
  95.         blt.s    @1
  96.         cmpi.b    #'z',d1
  97.         bgt.s    @1
  98.         add.b    #'A'-'a',d1
  99. @1
  100.         move.b    1(a1),d2
  101.         cmpi.b    #'a',d2
  102.         blt.s    @2
  103.         cmpi.b    #'z',d2
  104.         bgt.s    @2
  105.         add.b    #'A'-'a',d2
  106. @2
  107.         cmp.b    d2,d1
  108.         beq.s    @comp
  109.         blo.s    @out
  110.         moveq    #1,d0
  111.         bra.s    @out
  112. comp:    moveq    #0,d0
  113.         move.b    (a0)+,d0
  114.         swap    d0
  115.         move.b    (a1)+,d0
  116.         RelString
  117. out:;
  118.     }
  119. }
  120.  
  121. short foo;
  122.  
  123. static
  124. pascal Boolean myFilterProc(LocationNamePtr LNP, PortInfoPtr PIP) {
  125.     short    result = FALSE;
  126.     asm {
  127.         move.l    a4,-(a7)
  128.         lea        main,a4
  129.     }
  130.     if (PIP->name.portKindSelector == ppcByString) {
  131.         if (qRelString(PIP->name.u.portTypeStr, "\pMac Hax") == 0) {
  132.             result = TRUE;
  133.         }
  134.     }
  135.     asm {
  136.         move.l    (a7)+,a4
  137.     }
  138.     return result;
  139. }
  140.  
  141. static    short            broadcast;
  142. static    PPCOpenPBRec    PPCOpenRec;
  143. static    PPCPortRec        PPCPort;
  144. static    LocationNameRec    LNR;
  145. static    PortInfoRec        PIR;
  146.  
  147. PPCWritePBRec    Writer;
  148.  
  149. PPCStartPBRec    start;
  150.  
  151. static
  152. short setup(void) {
  153.     short    i;
  154.  
  155.     LNR.locationKindSelector = ppcNBPLocation;
  156.     PStringMove("\pMoof", LNR.u.nbpEntity.objStr);
  157.     PStringMove("\p=", LNR.u.nbpEntity.zoneStr);
  158.  
  159.     PIR.authRequired = FALSE;
  160.     PIR.name.nameScript = 0;    // smRoman;
  161.     PStringMove("\pInside Macintosh", PIR.name.name);
  162.     PIR.name.portKindSelector = ppcByString;
  163.     PStringMove("\pExample", PIR.name.u.portTypeStr);
  164.  
  165.     if (PPCBrowser("\pPrompt", "\pMice", FALSE, &LNR, &PIR, &myFilterProc, "\p") != noErr) return -1;
  166.  
  167. ////////////////////////
  168.  
  169.     PPCPort.nameScript = 0;    // smRoman;
  170.     PStringMove("\pKennedy Mouse", PPCPort.name);
  171.     PPCPort.portKindSelector = ppcByString;
  172.     PStringMove("\pKennedy Hax", PPCPort.u.portTypeStr);
  173.  
  174.     PPCOpenRec.ioCompletion = 0;
  175.     PPCOpenRec.serviceType = ppcServiceRealTime;
  176.     PPCOpenRec.resFlag = 0;
  177.     PPCOpenRec.portName = &PPCPort;
  178.     PPCOpenRec.locationName = 0;
  179.     PPCOpenRec.networkVisible = false;
  180.     if (PPCOpenSync(&PPCOpenRec) == noErr) {
  181.         start.ioCompletion = 0;
  182.         start.portRefNum = PPCOpenRec.portRefNum;
  183.         start.serviceType = ppcServiceRealTime;
  184.         start.resFlag = FALSE;
  185.         start.portName = &PIR.name;    // PPCPortRec *
  186.         start.locationName = &LNR;
  187.         start.userData = 'jbx!';
  188.         start.userRefNum = 0;
  189.         if (PPCStartSync(&start) == noErr) {
  190.             return 0;
  191.         } else {
  192.             return -1;
  193.         }
  194.         PPCCloseSync((void *)&PPCOpenRec);
  195.     } else {
  196.         return -1;
  197.     }
  198. }
  199.  
  200. EventRecord myEvent;
  201. struct {
  202.     Point    ms;
  203.     short    down;
  204. } MouseData, lastMD;
  205. short    lastButton;
  206.  
  207. VBLTask    InterruptDude = {
  208.     0,
  209.     vType,
  210.     0,
  211.     2,
  212.     0
  213. };
  214.  
  215. PPCWritePBRec    vWriter;
  216.  
  217. static short needShow, needHide;
  218.  
  219. static void myTask(void) {
  220.     void *oldA4 = SetA4(&main);
  221.  
  222.     InterruptDude.vblCount = 2;
  223.     
  224.     if (vWriter.ioResult <= 0) {
  225.         MouseData.ms = Mouse;
  226.         MouseData.down = MBState;
  227.         if (broadcast) {
  228.             if (MouseData.ms.h == 0 && MouseData.ms.v < 20) {
  229.                 broadcast = 0;
  230.                 MouseData.ms.h = CrsrPin.right - 10;
  231.                 *(Point *)0x828 = MouseData.ms;
  232.                 *(Point *)0x82C = MouseData.ms;
  233.                 *(Point *)0x830 = MouseData.ms;
  234.                 needShow = 1;
  235.             } else if (MouseData.ms.h >= CrsrPin.right - 1 && MouseData.ms.v < 20) {
  236.                 broadcast = 0;
  237.                 MouseData.ms.h = 10;
  238.                 *(Point *)0x828 = MouseData.ms;
  239.                 *(Point *)0x82C = MouseData.ms;
  240.                 *(Point *)0x830 = MouseData.ms;
  241.                 needShow = 1;
  242.             } else {
  243.                 if (lastMD.ms.h != MouseData.ms.h ||
  244.                     lastMD.ms.v != MouseData.ms.v ||
  245.                     lastMD.down != MouseData.down) {
  246.                     vWriter.ioCompletion = 0;
  247.                     vWriter.sessRefNum = start.sessRefNum;
  248.                     vWriter.more = FALSE;
  249.                     vWriter.userData = 0;
  250.                     vWriter.blockCreator = 'crea';
  251.                     vWriter.blockType = 'type';
  252.                     vWriter.bufferLength = 6;
  253.                     vWriter.bufferPtr = (void *)&MouseData;
  254.                     PPCWriteAsync(&vWriter);
  255.                     lastMD = MouseData;
  256.                 }
  257.             }
  258.         } else {
  259.             if (MouseData.ms.v < 20) {
  260.                 if (MouseData.ms.h < 1) {
  261.                     broadcast = 1;
  262.                     MouseData.ms.h = CrsrPin.right - 10;;
  263.                     *(Point *)0x828 = MouseData.ms;
  264.                     *(Point *)0x82C = MouseData.ms;
  265.                     *(Point *)0x830 = MouseData.ms;
  266.                     needHide = 1;
  267.                 } else if (MouseData.ms.h >= CrsrPin.right - 1) {
  268.                     broadcast = 1;
  269.                     MouseData.ms.h = 10;
  270.                     *(Point *)0x828 = MouseData.ms;
  271.                     *(Point *)0x82C = MouseData.ms;
  272.                     *(Point *)0x830 = MouseData.ms;
  273.                     needHide = 1;
  274.                 }
  275.             }
  276.         }
  277.     }
  278.  
  279.     InterruptDude.vblCount = 2;
  280.  
  281.     SetA4(oldA4);
  282. }
  283.  
  284. static void pJGNEFilter(void) {
  285.     static short recursion;
  286.     long    PPC_flags;
  287.  
  288.     GrafPtr oldPortPtr;
  289.  
  290.     if (recursion) return;
  291.     if (PPC_waiting < 0) return;
  292.     if (PPC_waiting == 1) {
  293.         if (Gestalt(gestaltPPCToolboxAttr, &PPC_flags) != noErr) return;
  294.         if (!(PPC_flags & gestaltPPCSupportsRealTime)) return;
  295.         recursion = 1;
  296.         PPC_waiting = setup();
  297.         if (PPC_waiting == 0) {
  298.             InterruptDude.vblAddr = (void *)&myTask;
  299.             VInstall((void *)&InterruptDude);
  300.         }
  301.         recursion = 0;
  302.         return;
  303.     }
  304.     if (needShow) {
  305.         needShow = 0;
  306.         ShowCursor();
  307.     }
  308.     if (needHide) {
  309.         needHide = 0;
  310.         HideCursor();
  311.     }
  312. }
  313.  
  314. static
  315. void GetTheEvent(void) {
  316.     EventRecord    myEvent;
  317.     if (GetOSEvent(mDownMask + mUpMask + keyDownMask, &myEvent)) {
  318.         Writer.ioCompletion = 0;
  319.         Writer.sessRefNum = start.sessRefNum;
  320.         Writer.more = FALSE;
  321.         Writer.userData = 0;
  322.         Writer.blockCreator = 'crea';
  323.         Writer.blockType = 'type';
  324.         Writer.bufferLength = sizeof(myEvent);
  325.         Writer.bufferPtr = (void *)&myEvent;
  326.         PPCWriteAsync(&Writer);
  327.     //    while (Writer.ioResult > 0);
  328.     }
  329. }
  330.  
  331. void pPostEvent(void) {
  332.     asm {
  333.         subq    #4,a7
  334.         move.l    a4,-(a7)
  335.         lea        main,a4
  336.         move.l    oldPostEvent,4(a7)
  337.         tst.w    broadcast
  338.         beq.s    @out
  339.         pea        @ovr
  340.         move.l    oldPostEvent,-(a7)
  341.         rts
  342. ovr:    movem.l    d0/d1/d2/a0/a1,-(a7)
  343.         jsr        GetTheEvent
  344.         movem.l    (a7)+,d0/d1/d2/a0/a1
  345.         move.l    (a7)+,a4
  346.         addq    #4,a7
  347.         rts
  348. out:    move.l    (a7)+,a4
  349.     }
  350. }
  351.  
  352. void pButton(void) {
  353.     asm {
  354.         subq    #4,a7
  355.         move.l    a4,-(a7)
  356.         lea        main,a4
  357.         move.l    oldButton,4(a7)
  358.         tst.w    broadcast
  359.         beq.s    @dn
  360.         move.l    (a7)+,a4
  361.         addq    #4,a7
  362.         clr.w    4(a7)
  363.         rts
  364. dn:        move.l    (a7)+,a4
  365.     }
  366. }